import util from '../../utils/util.js'
import {getOrderListModel} from '../../models/method.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isActive: 0,
    status: '',
    page: 1,
    scrollHeight: 0,
    moneyAmount: 0, //总金额
    payMoneyAmount: 0, //总支付金额
    noMore: false,
    counts: 0,
    height: '0rpx',
    isShade: true,
    order_id:'',
    orderData: []
  },
  onLoad: function () {
    this._orderRequest()
    this._scrollHeight()
  },

  //去支付
  goPayment(e) {
    this.setData({
      height: '700rpx',
      isShade: false,
      order_id: e.currentTarget.dataset.item.order_oil_id,
      orderData: e.currentTarget.dataset.item
    })
    console.log(e.currentTarget.dataset.item)
  },
  //关闭支付
  closeDetail() {
    this.setData({
      height: '0rpx',
      isShade: true,
    })
  },
  //计算高度
  _scrollHeight() {
    const height = 400;
    const scrollHeight = util.scrollHeight(height)
    this.setData({
      scrollHeight
    })
  },
  //加载数据
  _orderRequest(status = '', page = 1) {
    const limit=6
    if (page == 1) {
      this.setData({
        orderList: []
      })
    }
    this.setData({
      noMore: false
    })
    wx.showNavigationBarLoading()
    getOrderListModel(page,status,limit)
      .then((res => {
        console.log(res)
        const item = res.data
        const moneyAmount = item.moneyAmount
        const payMoneyAmount = item.payMoneyAmount
        const counts = item.counts
        let list = this.data.orderList
        let orderList = list.concat(item.list)
        this.setData({
          orderList,
          status,
          page,
          moneyAmount,
          payMoneyAmount,
          counts
        })
        wx.hideNavigationBarLoading()
        if (orderList.length == this.data.counts) {
          this.setData({
            noMore: true
          })
        }
        console.log(orderList)
      }))
  },
  //点击全部
  clickAll() {
    if (this.data.isActive !== 0) {
      this.setData({
        isActive: 0
      })
      this._orderRequest()
    }
  },
  //点击待支付
  clickUnpaid() {
    if (this.data.isActive !== 1) {
      this.setData({
        isActive: 1
      })
      this._orderRequest('unpaid')
    }
  },
  //点击已退款
  clickRefund() {
    if (this.data.isActive !== 2) {
      this.setData({
        isActive: 2
      })
      this._orderRequest('refund')
    }
  },
  //点击已支付
  clickPayment() {
    if (this.data.isActive !== 3) {
      this.setData({
        isActive: 3
      })
      this._orderRequest('paid')
    }
  },
  //下滑加载更多
  scrollDown() {
    this.data.page++
    this._orderRequest(this.data.status, this.data.page)
  },
  //跳转
  clickOrderLsit(e) {
    wx.navigateTo({
      url: `../orderDetails/orderDetails?id=${e.currentTarget.dataset.id}`
    })


  },
  // 分享
  onShareAppMessage() {

  }

})